'use strict';

export default class extends think.controller.base {
  /**
    * some base method in here
    */
  //public let admin_user = '';
  init(http) {
    super.init(http);
    this.assign({
      ADMIN_PATH: this.config('admin_path'),
      COPY_RIGHT: this.config('copy_right'),
      INC_PATH: this.config('inc_path'),
      __PUBLIC__:this.config('publich_path'),
    });

  }

  //初始化前台信息
  async __before() {

    this.actionName = this.http.action;
    let isLogin = await this.checkLogin();
    if (this.actionName != 'login' && this.actionName != 'dologin') {
      if (!isLogin) {
        return this.redirect('/admin/public/login');
      }
      this.user = await this.session('admin');
    } else {
      if (isLogin) {
        return this.redirect('/admin/index');
      }
    }
  }

  //判断与获取login 的信息
  async checkLogin() {
    let user = await this.session('admin');
    let res = think.isEmpty(user) ? false : user;
    return res;
  }
}